package alt.djudge.frontend.server.servlets.gwt;

import java.util.List;

import org.apache.log4j.Logger;

import alt.djudge.frontend.client.rpc.DJudgeGWTContestService;
import alt.djudge.frontend.client.rpc.DJudgeGWTPublicService;
import alt.djudge.frontend.server.datatypes.ContestEntry;
import alt.djudge.frontend.server.models.ContestsModel;
import alt.djudge.frontend.shared.dto.contest.ContestInfoDTO;


public class DJudgeGWTPublicServiceImpl extends DJudgeGwtRpcServlet implements DJudgeGWTPublicService
{
	private static final long serialVersionUID = 1L;
	
	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(DJudgeGWTContestService.class);

	@Override
	public ContestInfoDTO[] getContests(int page)
	{
		List<ContestEntry> contests = ContestsModel.getAllEntries();
		int sz = contests.size();
		ContestInfoDTO[] result = new ContestInfoDTO[sz];
		for (int i = 0; i < sz; i++)
		{
			ContestEntry contest = contests.get(i);
			ContestInfoDTO contestInfoDTO = contest.asContestInfoDTO();
			result[i] = contestInfoDTO;
		}
		return result;
	}

}
